package day05;

/**
 * @author Smartloe
 * @create 2021-04-04 17:10
 */
public class PrimeNumberTest1 {
    public static void main(String[] args) {
        boolean isFlag = true;
       long start =  System.currentTimeMillis();
        for (int i = 2; i <= 10000000; i++) {
//            boolean isFlag = true;
            //优化二：对本身是质数的自然数是有效的
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if (i%j == 0){
                    isFlag = false;
                    break;//优化一：只对非质数的自然数是有效的
                }
            }
            if (isFlag == true){
                System.out.println(i);
            }
            isFlag = true;
        }
        long end = System.currentTimeMillis();
        System.out.println("所花费的时间为："+(end-start));
    }
}